Preserving Code Formats with CodeSweepers

The CodeSweeper feature automates the task of getting your code properly formatted. It can be very useful in a number of situations:

Selecting a CodeSweeper

Studio includes a number of CodeSweepers, configured for specific types of development. You can also create your own CodeSweepers or edit the existing ones.

Allaire CodeSweepers

Installed CodeSweepers include:

HTML Tidy

HTML Tidy, a tool developed by Dave Ragget under the auspices of the W3C, is installed as an alternate to the Allaire CodeSweepers. HTML Tidy provides code formatting options plus settings for tag conversions, language support, and other features not available in the Allaire CodeSweepers.

Select Options > Settings > CodeSweeper and expand HTML Tidy CodeSweepers to view and set options.

You can easily update the HTML Tidy engine if new features are added to between HomeSite releases.

Note To install a newer version of HTML Tidy:
  1. Click the link at the top of the HTML Tidy settings dialog the HTML Tidy Web site.
  2. Download the latest version from the site.
  3. Close HomeSite.
  4. Copy the tidy.exe files to your HomeSite root directory.
  5. Restart HomeSite.

Your HTML Tidy configuration is not affected by the update.

Running a CodeSweeper

Open the Tools > CodeSweeper menu to select a CodeSweeper or click the CodeSweeper button on the Tools toolbar to run the default on the current document. Click the down arrow button next to the CodeSweeper button to select from the list of available CodeSweepers.

Note To set the default CodeSweeper:
  1. Open Options > Settings > CodeSweeper.

  2. Highlight a CodeSweeper entry in the list and click the Set as Default button.
  3. Click OK to save the change.
Note To run a CodeSweeper automatically after leaving Design mode:
  1. In Options > Settings Design, clear the Disable (hide) design tab option.
  2. Select whether to display a warning message when leaving Design View.
  3. Click the Apply CodeSweeper when return from design view button.
  4. Click the CodeSweeper Settings button if you want to edit CodeSweepers.

Managing CodeSweepers

You can create new CodeSweepers, edit existing ones, and remove them as needed.

Note To add a new CodeSweeper:
  1. Click the New Profile button in the Allaire CodeSweepers panel.
  2. Enter a name for the CodeSweeper and select its type: Allaire or HTML Tidy.
  3. Click OK to add it to the list.
  4. Follow the directions in the next procedure to create a custom profile for the new CodeSweeper.
Note To edit a CodeSweeper:
  1. Highlight a CodeSweeper in the list and click the Edit Profile button.
  2. Make changes to the General and Tag Specific settings and click OK to save the new profile.

To delete a CodeSweeper, highlight it and click the Remove CodeSweeper button.

Allaire CodeSweeper settings

These settings apply only to Allaire CodeSweepers. HTML Tidy Codesweeper settings are covered in the next section.

To begin, open the Options > Settings > CodeSweeper pane.

General settings

Allaire CodeSweepers treat the colon character (:) in tag names as a normal character, allowing processing of XML namespaces in tags, such as <xsl:thistag name="foo"/>.

Tag-specific settings

A wide range of options is available for the individual tags contained in an Allaire CodeSweeper.

These settings cover spacing and indenting and allow you to leave the selected tag unchanged when invoking the CodeSweeper. If you are encountering problems parsing server-based script code, then enable the Preserve tag formatting option.

Tip The Strip tag from document option is handy for getting rid of superfluous and unwanted tags inserted by code generation tools.

Note To set rules for a tag:
  1. Select a CodeSweeper from the list.
  2. Edit the General Settings as needed.
  3. Switch to the Tag Specific Settings tab and highlight a tag name in the list.

    Note that if you select the "All Other Tags" entry in the list, the rules that you select will apply to every tag not in the list that is found in a document.

  4. Edit the settings for the tag.
  5. Click Update Tag to save the settings for that tag.
Note To add a tag and apply formatting rules:
  1. Click the Add Tag button in the Tag Specific tab.
  2. Enter the tag name and click OK.
  3. Set rules for the tag and click Update Tag to save the settings.

To remove a tag, highlight it and click the Remove Tag button.

HTML Tidy settings

Adding a profile

Creating a custom HTML Tidy profile is much like creating one for an Allaire CodeSweeper.

Note To create an HTML Tidy profile:
  1. Click the New Profile button in the HTML Tidy CodeSweeper dialog box.
  2. Enter a profile name.
  3. Select HTML Tidy from the drop-down CodeSweeper type list and click OK.

    A default set of options is preselected.

  4. Highlight the CodeSweeper in the list and click Edit Profile.
  5. Change the settings as you want and click OK to save the new profile.

Editing a profile

The HTML Tidy CodeSweepers pane gives you access to all the supported settings, but you can also edit a profile directly. This can be useful in a couple of situations:

The HTML Tidy Web site lists new features and the correct syntax for enabling them.

Be sure to backup the original TDY file before making changes.

Note To edit an HTML Tidy profile:
  1. Open the TDY file from \Extensions\Codesweepers.
  2. Edit the name:value pairs as needed.
  3. Save the file.

    The changes are reflected in the HTML Tidy CodeSweeper pane.

To remove an HTML Tidy profile, delete the tdy file.